<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Document</title>
</head>
<body>
    <form>
        <input type="text" name="uname" id="uname" value="">
        <input type="password" name="upwd" id="upwd" value="">
        <input type="button" onclick="login()" value="登录">
    </form>
    <script>
        function login(){
            var uname = document.getElementById('uname');
            var upwd = document.getElementById('upwd');
            if(!uname.value){
                alert('请输入用户名')
            }
            if(!upwd.value){
                alert('请输入密码')
            }
            //1.创建xhr对象
            var xhr = new XMLHttpRequest();
            //2.指定接收函数
            xhr.onreadystatechange = function(){
                if(xhr.readyState==4 && xhr.status==200){
                    var rs = xhr.responseText;
                    if(rs==1){
                        alert("登录成功");
                        // location.href='https://www.baidu.com'
                    }else{
                        alert("登陆失败")
                    }
                }
            }
            //3.连接服务器
            url = `http://127.0.0.1:8080/pro/v1/login`;
            xhr.open('post',url,true);
            // 设置请求头
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            //发送
            xhr.send(`uname=${uname.value}&upwd=${upwd.value}`);
        }
    </script>
</body>
</html>